var table = layui.table;
$(document).ready(function() {
    //初始化数据列表
    load();
});

function getQueryString(name) {

    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return r[2];
    }else{
        if (!location.hash) return ''
        var regHash = new RegExp("(^|&|\\?)" + name + "=([^&]*)(&|$)");
        var rHash = location.hash.slice(1).match(regHash);
        return  rHash != null ?  rHash[2] : ''
    }
    return '';
}


function load() {
    table.render({
        id: 'news',
        elem: '#news',
        method: 'post',
        url:'/api/user/news',
        skin:'line',
        limit: 10, //每页默认显示的数量
        response: {
            statusCode: 200
        },
        where:{
            id:getQueryString("id")
        },
        cols: [[
            {field:'title', title: '信息标题',templet:function(row){
                return '<a href="/api/user/center_content.html?pid='+row.parentClassify.id+'&id='+row.childClassify.id+'&contId='+row.id+'">'+row.title+'</a>';
             }},
            {field:'publishDate', title: '发布时间',align:"right"}
        ]],
        done: function (res, curr, count) {
            $('.layui-table .layui-table-cell > span').css({'font-weight': 'bold'});//表头字体样式
            /*$('th').css({'background-color': '#5792c6', 'color': '#fff','font-weight':'bold'}) 表头的样式 */
            $('th').hide();//表头隐藏的样式
            //$('.layui-table-page').css('margin-top','40px');//页码部分的高度调整
        },
        page: true
    });

    $("#searchBtn").click(search);
}

function initRightToolbar() {
    table.on('tool(news)', function(obj){
        if(obj.event === 'allInfo_detail') {
            allInfoDetail(obj);
        }
        if(obj.event === 'allInfo_del') {
            allInfoDel(obj);
        }
    });
}

/**
 * 详情按钮
 * @param obj
 */
function allInfoDetail(obj) {
    layer.open({
        type: 2,
        title: '详情',
        fix: false,
        resize: false,
        area: ['680px', '400px'],
        btn: ['关闭'],
        content: '/all/info/toDetail/' + obj.data.id,
    });
}


/**
 * 查询按钮
 */
function search() {
    table.reload('news', {
        page: {
            curr: 1
        },
        where: {title: $("#title").val(),conType:$("#conType").val(),
            status: $("#status").val(),createTime: $("#createTime").val(),beginDate:$("#beginDate").val(),
            endDate:$("#endDate").val(),dept:$("#dept").val(),createName:$("#createName").val()}
    });
}

